package com.admin.business.transitionVateUserInfo;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 用户投票记录表
 * @create: 2023-10-13 09:55:57
 **/
@Service("transitionVateUserInfoService")
@Slf4j
public class TransitionVateUserInfoService{

    @Resource
    TransitionVateUserInfoDao transitionVateUserInfoDao;

    /**
     * 添加用户投票记录表,获取id数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - user_id_vate:被投票用户id
     *                   - vate_info_id:投票发起记录id
     *                   - user_vate_state:投票状态：0工作组投票，1委员投票，2文件投票
     *                   - word_state:状态：1同意 0不同意
     *                   - vate_content:内容
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return addTransitionVateUserInfo(CDO cdoRequest) {
        transitionVateUserInfoDao.addTransitionVateUserInfo(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新用户投票记录表数据
     *
     * @param cdoRequest - id:
     *                   - user_id:用户id
     *                   - user_id_vate:被投票用户id
     *                   - vate_info_id:投票发起记录id
     *                   - user_vate_state:投票状态：0工作组投票，1委员投票，2文件投票
     *                   - word_state:状态：1同意 0不同意
     *                   - vate_content:内容
     *                   - update_time:更新时间
     *                   - begin_time:创建时间
     *                   - state:删除，0正常1删除
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return updateTransitionVateUserInfoById(CDO cdoRequest) {
        transitionVateUserInfoDao.updateTransitionVateUserInfoById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除用户投票记录表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return deleteTransitionVateUserInfoById(CDO cdoRequest){
        int count = transitionVateUserInfoDao.deleteTransitionVateUserInfoById(cdoRequest.getInteger("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除用户投票记录表数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return deleteTransitionVateUserInfo(CDO cdoRequest) {
        int count = transitionVateUserInfoDao.deleteTransitionVateUserInfo(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取用户投票记录表数据
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return getTransitionVateUserInfoById(CDO cdoRequest) {
        CDO cdoMapperResult = transitionVateUserInfoDao.getTransitionVateUserInfoById(cdoRequest.getInteger("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取用户投票记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return getTransitionVateUserInfoListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = transitionVateUserInfoDao.getTransitionVateUserInfoListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = transitionVateUserInfoDao.getTransitionVateUserInfoCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取用户投票记录表数据列表
     *
     * @param cdoRequest - id:
     * @return
     * @author wdf
     * @create: 2023-10-13 09:55:57
     */
    @OpenApi
    public Return getTransitionVateUserInfoListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = transitionVateUserInfoDao.getTransitionVateUserInfoListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = transitionVateUserInfoDao.getTransitionVateUserInfoCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
